using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;

namespace Admin.NET.Application.Util;

public class UtilCertDic
{
	private static Dictionary<string, X509Certificate2> UtilDic = new Dictionary<string, X509Certificate2>();

	private static object lockdic = new object();

	public static bool GetCertDic(string key, out X509Certificate2 certificate2)
	{
		return UtilDic.TryGetValue(key, out certificate2);
	}

	/// <summary>
	/// 新增
	/// </summary>
	/// <param name="key"></param>
	/// <param name="x509Certificate2"></param>
	/// <param name="delCert"></param>
	public static void SetCertDic(string key, X509Certificate2 x509Certificate2, string delCert = null)
	{
		lock (lockdic)
		{
			if (delCert != null)
			{
				UtilDic.Remove(delCert);
			}
			if (UtilDic.ContainsKey(key))
			{
				UtilDic.Remove(key);
			}
			UtilDic.Add(key, x509Certificate2);
		}
	}
}
